import java.util.Stack;

class Solution {
    public boolean isValid(String s) {
       Stack<Character> stack = new Stack<>() ;
       for(int i = 0 ; i < s.length() ; i++){
           char tmp = s.charAt(i) ;
           if(tmp == '(' || tmp == '[' || tmp == '{' ){
              stack.push(tmp) ;
           }else{
               if(stack.empty()){
                   return false ;
               }
               char get = stack.pop() ;
              if(tmp == ')' && get != '('){
                  return false ;
              }
               if(tmp == ']' && get != '['){
                  return false ;
              } if(tmp == '}' && get != '{'){
                  return false ;
              }
           }
       }

       return stack.empty() ;

    }
}